<template>
  <div>
    <el-card class="update-log msg-table-list" style="height: 366px;">
      <div slot="header" class="clearfix">
        <span>到期证书（<span class="badge-arrow-num">{{this.total}}</span>）</span>
        <span class="header-more-title">
          <template >
            <router-link :to="'/cert/certInfo'" class="link-type">
              <span>更多<i class="el-icon-arrow-right"></i></span>
            </router-link>
          </template>
        </span>
      </div>
      <div class="body">
        <el-table v-loading="loading" :data="form" @row-click="handlePostpone" style="width: 100%;" :show-header="false">
          <template slot-scope="scope">
            <el-table-column prop="username" width="80" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="certNumber" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column width="100px" prop="endDate">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
          </template>
        </el-table>
      </div>
    </el-card>

    <!-- 处理证书延期对话框 -->
    <!--<el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-form ref="form" :inline="true" :model="postponeForm" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-table :data="postponeForm.certInfoList" >
              <el-table-column
                label="工号"
                align="center"
                prop="staffNo"
                :show-overflow-tooltip="true"
              />
              <el-table-column
                label="姓名"
                align="center"
                prop="username"
                :show-overflow-tooltip="true"
              />

              <el-table-column
                label="编号"
                align="center"
                prop="certNumber"
                :show-overflow-tooltip="true"
              />

              <el-table-column
                label="证书名称"
                align="center"
                prop="certName"
                :show-overflow-tooltip="true"
              />

              <el-table-column
                label="项目代码"
                align="center"
                prop="projectCode"
              />

              <el-table-column label="取证日期" align="center" prop="obtainEvidenceDate">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.obtainEvidenceDate, '{y}-{m}-{d}') }}</span>
                </template>
              </el-table-column>

              <el-table-column label="截止时间" align="center" prop="endDate">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
                </template>
              </el-table-column>

              <el-table-column
                label="有效期（年）"
                align="center"
                prop="reviewPeriod"
              />
            </el-table>
          </el-col>
        </el-row>

        <el-row style="margin-top: 20px">
          <el-col :span="12">
            <el-form-item label="延期原因" prop="cause">
              <el-input
                v-model="postponeForm.cause"
                placeholder="请输入原因"
                clearable
                size="small"
              />
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">提 交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>-->
  </div>

</template>

<script>
  import {selectCertByYear,postponeCert} from "@/api/cert/certInfo";

  export default {
    name: 'CertTable',
    data() {
      return {
        // 遮罩层
        loading: true,
        // 本年未处理证书列表
        form: [],
        // 延期表单
        postponeForm:{
            // 延期证书列表
          certInfoList: [],
        },
        //证书总数
        total: 0,
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
        },
        // 表单校验
        rules: {
          cause: [
            {required: true, message: "原因不能为空", trigger: "blur"}
          ],
        },
      }
    },
    created() {
      //初始化证书列表
      this.initList();
    },
    methods: {
      //初始化未处理证书列表
      initList() {
        this.loading = true;
        selectCertByYear(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.form = response.responseBody.result;
          this.total = response.responseBody.pageParameter.totalCount;
          this.loading = false;
        });
      },
      /** 查询详情修改操作 */
      handlePostpone(row) {
        // var arry = [row];
        // this.postponeForm.certInfoList = arry;
        // this.open = true;
        // this.title = "证书延期";
        /*selectCertInfoByCertId().then(response => {
          this.postponeForm.certInfoList = Object.values(row);
          this.open = true;
          this.title = "证书延期";
        });*/
      },
      // 取消按钮
      cancel() {
        this.open = false;
      },
      /** 提交按钮 */
      submitForm: function() {
      //   this.$refs["form"].validate(valid => {
      //     if (valid) {
      //       if (this.postponeForm.certInfoList != null) {
      //         postponeCert(this.postponeForm).then(response => {
      //           this.msgSuccess("提交成功！");
      //           this.open = false;
      //           //初始化消息列表
      //           this.initList();
      //         });
      //       }
      //     }
      //   });
      },
    }
  }
</script>
